package com.fyb.aicar.config;

import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.Yaml;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

@Component
public class PromptTemplate {
    private static final Map<String, Object> TEMPLATE;

    static {   // 只加载一次
        Yaml yaml = new Yaml();
        try (InputStream in = PromptTemplate.class.getResourceAsStream("/prompt/auto-repair.yml")) {
            Map<String, Object> obj = yaml.load(in);
            TEMPLATE = Map.of("system", obj.get("system"), "user", obj.get("user"));
        } catch (IOException e) {
            throw new RuntimeException("加载提示词模板失败", e);
        }
    }

    public static String system() { return (String)TEMPLATE.get("system"); }
    public static String user() { return (String) TEMPLATE.get("user"); }

//    public static String user(Map<String, Object> params) {
//        return StrSubstitutor.replace(TEMPLATE.get("user"), params);
//    }
}